package sistemaAcademico.interfaceUsuario.disciplinaMVC.controle;

import java.util.ArrayList;

import sistemaAcademico.interfaceUsuario.CursoMVC.excecao.CursoSemCodigoException;
import sistemaAcademico.interfaceUsuario.CursoMVC.view.CursoView;
import sistemaAcademico.interfaceUsuario.disciplinaMVC.excecao.DisciplinaNaoEncontradaException;
import sistemaAcademico.interfaceUsuario.disciplinaMVC.excecao.DisciplinaSemCodigoException;
import sistemaAcademico.interfaceUsuario.disciplinaMVC.view.DisciplinaView;
import sistemaAcademico.negocio.Curso;
import sistemaAcademico.negocio.Disciplina;

public class DisciplinaControlador {
	
	public static void carregar(DisciplinaView view) throws DisciplinaSemCodigoException, DisciplinaNaoEncontradaException {
		Disciplina d = view.getDisciplina();
		if (d.getCodigo().equals(" "))
			throw new DisciplinaSemCodigoException();
		else {
			d = new Disciplina(d.getCodigo());
			if (d.getNome() == null)
				throw new DisciplinaNaoEncontradaException();
			else
				view.setDisciplina(d);			
		}
	}
	
	public static void salvar(DisciplinaView view) throws DisciplinaSemCodigoException {
		Disciplina d = view.getDisciplina();
		if (!d.getCodigo().equals(" "))			
			d.salvar();
		else
			throw new DisciplinaSemCodigoException();
	}
	
	public static void update(DisciplinaView view) throws DisciplinaSemCodigoException {
		Disciplina d = view.getDisciplina();
		if (!d.getCodigo().equals(" "))
			d.update();
		else
			throw new DisciplinaSemCodigoException();
	}
	
	public static void remover(DisciplinaView view) throws DisciplinaSemCodigoException {
		Disciplina d = view.getDisciplina();
		if (!d.getCodigo().equals(" "))			
			d.remover();
		else
			throw new DisciplinaSemCodigoException();
	}
	
	public static String[][] getMatrizDisciplina() {
		ArrayList<Disciplina> disciplinas = Disciplina.getLista();
		
		String[][] matriz = new String[disciplinas.size()][6];
		
		int i = 0;
		for (Disciplina d : disciplinas) {
			matriz[i][0] = d.getCodigo();
			matriz[i][1] = d.getNome();
			matriz[i][2] = String.valueOf(d.getCargaHoraria());
			matriz[i][3] = d.getResumo();
			matriz[i][4] = String.valueOf(d.getCreditosTeoricos());
			matriz[i][5] = String.valueOf(d.getCreditosPraticos());
			
			i++;
		}
		
		return matriz;
	}
}
